package com.example.crawler.controller;

import com.google.common.collect.Lists;
import net.sourceforge.tess4j.ITesseract;

import com.alibaba.fastjson.JSONObject;
import com.example.crawler.mapper.CrawlerIndustryMapper;
import com.example.crawler.utils.SendHttpsRequestUtil;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.net.ssl.HttpsURLConnection;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

import okhttp3.*;
//import org.json.JSONObject;

import java.io.*;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;


@Controller
@RequestMapping("/crawlerIndustry/")
//@Component
public class CrawlerIndustrySchedule {

    private static Logger logger = LoggerFactory.getLogger(CrawlerIndustrySchedule.class);

    @Resource
    private CrawlerIndustryMapper crawlerIndustryMapper;


    /**
     * 1. 爬取公告名称 + 发布日期
     */
//    @XxlJob("orgDataSchedule")
    @GetMapping(value = "/getComList")
    public void orgDataSchedule() {
//        XxlJobHelper.log("XXL-JOB, orgDataSchedule.");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            long start = System.currentTimeMillis();
            logger.info(String.format("开始爬取数据: %s", start));

            List<Map<String, String>> resultDateList = new ArrayList<>();

            // 1. 爬取结果
            String urlHead = "https://www.miit.gov.cn/api-gateway/jpaas-publish-server/front/page/build/unit?webId=8d828e408d90447786ddbe128d495e9e&pageId=ebb511ab5c974de38b61bdc0198ce370&parseType=buildstatic&pageType=column&tagId=%E5%BD%93%E5%89%8D%E6%A0%8F%E7%9B%AE_list&tplSetId=209741b2109044b5b7695700b2bec37e&paramJson=";
            String url = "%7B%22pageNo%22%3A1%2C%22pageSize%22%3A%2224%22%7D";
            String pageData = SendHttpsRequestUtil.post(urlHead + url, null);

            // 2. 处理爬取数据 + 判断页数
            // 2.1 爬取后面页的数据 -- 页数循环 + 汇总数据
            Map pageMap = JSONObject.parseObject(pageData, Map.class);
            Document pageDocument = Jsoup.parse(((Map) pageMap.get("data")).get("html") + "");
            String count = pageDocument.getElementsByClass("pagination").first().attr("count");
            String rows = pageDocument.getElementsByClass("pagination").first().attr("rows");
            int pageNum = Integer.parseInt(count) / Integer.parseInt(rows) + 1;
            String urlDec = URLDecoder.decode(url, "UTF-8");
            if (pageDocument.getElementsByTag("li").text().contains(sdf.format(new Date()))) {
                for (int i = 1; i <= pageNum; i++) {
                    String urlEnc = URLEncoder.encode(urlDec.replace("\"pageNo\":1", "\"pageNo\":" + i), "UTF-8");
                    String resultDataStr = SendHttpsRequestUtil.post(urlHead + urlEnc, null);
                    Map dataMap = JSONObject.parseObject(resultDataStr, Map.class);
                    Document dataDocument = Jsoup.parse(((Map) dataMap.get("data")).get("html") + "");

                    // 2.1 判断今天，是否有公告发布
                    Elements publicNameDateList = dataDocument.getElementsByTag("li");  // 公告名称 + 日期
                    if (publicNameDateList.text().contains(sdf.format(new Date()))) {
                        for (Element element : publicNameDateList) {
                            Map<String, String> tempMap = new HashMap<>();
                            if (sdf.format(new Date()).equals(element.getElementsByTag("span").text())) {
                                tempMap.put("bulletin_url", "https://www.miit.gov.cn" + element.getElementsByTag("a").attr("href"));   // 公告url
                                tempMap.put("bulletin_name", element.getElementsByTag("a").text());         // 公告名称
                                tempMap.put("public_date", element.getElementsByTag("span").text());        // 公告日期
                                tempMap.put("create_time", sdf.format(new Date()));// 公告日期
                                System.out.println(tempMap);
                                resultDateList.add(tempMap);
                            }
                        }
                    }
                }
            }

            // 2.3 汇总入库数据
            if (!CollectionUtils.isEmpty(resultDateList)) {
                crawlerIndustryMapper.insert(resultDateList);
            }

            logger.info(String.format("爬取数据完成耗时: %s", System.currentTimeMillis() - start));
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }


    /**
     * 2. 爬取公告详细数据
     */
//    @XxlJob("orgDataSchedule")
    @GetMapping(value = "/getComList2")
    public void orgDataSchedule2() {
//        XxlJobHelper.log("XXL-JOB, orgDataSchedule.");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            long start = System.currentTimeMillis();
            logger.info(String.format("开始爬取数据: %s", start));

            String urlHead = "https://www.miit.gov.cn";

            // 1. 查询公告内容

            // 2. 判断文件格式

            // 3. 读取所需要的数据
            // 截取图片的名称
            String imageUrl = "https://www.miit.gov.cn/cms_files/filemanager/1226211233/picture/202210/9cd4ec9ac6584eb38a3c7569cd9e81ac.png";
            boolean downFlag = SendHttpsRequestUtil.postPicture("D:/", imageUrl);
            if (downFlag) {
                // 3.1 读取数据

            }

            // 4. 数据入库

            logger.info(String.format("爬取数据完成耗时: %s", System.currentTimeMillis() - start));
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }

    /**
     * 3. tess4j 识别图片文字
     */
//    @XxlJob("orgDataSchedule")
    @GetMapping(value = "/getComList3")
    public void getComList3() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            long start = System.currentTimeMillis();
            logger.info(String.format("开始识别数据: %s", start));

            String lagnguagePath = "D:\\baseEnvironment\\tessdata";
            String filePath = "D:/picture/2.png";
            File file = new File(filePath);

            // 语言库位置
            // 创建解析对象
            ITesseract instance = new Tesseract();
            // 设置训练库的位置
            instance.setDatapath(lagnguagePath);
            // chi_sim :简体中文，eng根据而求选择语言库
            instance.setLanguage("chi_sim");

            String result = null;
            try {
                result = instance.doOCR(file);
            } catch (TesseractException e) {
                e.printStackTrace();
            }

            System.out.println("result:");
            System.out.println(result);


            logger.info(String.format("识别图片完成耗时: %s", System.currentTimeMillis() - start));
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }


    static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();

    /**
     * 4. 百度API 识别图片文字
     */
//    @XxlJob("orgDataSchedule")
    @GetMapping(value = "/baiduOcr")
    public void baiduOcr() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            long start = System.currentTimeMillis();
            logger.info(String.format("开始识别数据: %s", start));

            MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
            // image 可以通过 getFileContentAsBase64("C:\fakepath\2.png") 方法获取,如果Content-Type是application/x-www-form-urlencoded时,使用getFileContentAsBase64Urlencoded方法获取
            RequestBody body = RequestBody.create(mediaType, "image=iVBORw0KGgoAAAANSUhEUgAAAjwAAAKNCAYAAAAkmbFKAAAgAElEQVR4AeydBVhVSRvHfwgGCIgBIhIiCogitljY3Ynd7Rq7tq5r...&cell_contents=true");
//            Request request = new Request.Builder()
//                    .url("https://aip.baidubce.com/rest/2.0/ocr/v1/table?access_token=24.a7d88c990c4fb6fa52621fabc7c750d1.2592000.1682062331.282335-31533353")
//                    .method("POST", body)
//                    .addHeader("Content-Type", "application/x-www-form-urlencoded")
//                    .addHeader("Accept", "application/json")
//                    .build();
//            Response response = HTTP_CLIENT.newCall(request).execute();
//            System.out.println(response.body().string());
            String responseStr = "{\"tables_result\":[{\"header\":[{\"location\":[{\"x\":143,\"y\":6},{\"x\":434,\"y\":6},{\"x\":434,\"y\":22},{\"x\":143,\"y\":22}],\"words\":\"工业和信息化部通报存在问题的APP名单\"}],\"body\":[{\"col_end\":1,\"row_end\":1,\"cell_location\":[{\"x\":8,\"y\":25},{\"x\":53,\"y\":25},{\"x\":53,\"y\":66},{\"x\":8,\"y\":66}],\"row_start\":0,\"col_start\":0,\"words\":\"序号\",\"contents\":[{\"poly_location\":[{\"x\":13,\"y\":38},{\"x\":44,\"y\":38},{\"x\":44,\"y\":56},{\"x\":13,\"y\":56}],\"word\":\"序号\"}]},{\"col_end\":2,\"row_end\":1,\"cell_location\":[{\"x\":53,\"y\":25},{\"x\":126,\"y\":25},{\"x\":126,\"y\":66},{\"x\":53,\"y\":66}],\"row_start\":0,\"col_start\":1,\"words\":\"应用名称\",\"contents\":[{\"poly_location\":[{\"x\":57,\"y\":39},{\"x\":114,\"y\":39},{\"x\":114,\"y\":55},{\"x\":57,\"y\":55}],\"word\":\"应用名称\"}]},{\"col_end\":3,\"row_end\":1,\"cell_location\":[{\"x\":126,\"y\":25},{\"x\":237,\"y\":25},{\"x\":237,\"y\":66},{\"x\":126,\"y\":66}],\"row_start\":0,\"col_start\":2,\"words\":\"应用开发者\",\"contents\":[{\"poly_location\":[{\"x\":142,\"y\":39},{\"x\":213,\"y\":39},{\"x\":213,\"y\":55},{\"x\":142,\"y\":55}],\"word\":\"应用开发者\"}]},{\"col_end\":4,\"row_end\":1,\"cell_location\":[{\"x\":237,\"y\":25},{\"x\":325,\"y\":25},{\"x\":325,\"y\":66},{\"x\":237,\"y\":66}],\"row_start\":0,\"col_start\":3,\"words\":\"应用来源\",\"contents\":[{\"poly_location\":[{\"x\":249,\"y\":39},{\"x\":306,\"y\":39},{\"x\":306,\"y\":55},{\"x\":249,\"y\":55}],\"word\":\"应用来源\"}]},{\"col_end\":5,\"row_end\":1,\"cell_location\":[{\"x\":325,\"y\":25},{\"x\":395,\"y\":25},{\"x\":395,\"y\":66},{\"x\":325,\"y\":66}],\"row_start\":0,\"col_start\":4,\"words\":\"应用版本\",\"contents\":[{\"poly_location\":[{\"x\":329,\"y\":39},{\"x\":387,\"y\":39},{\"x\":387,\"y\":55},{\"x\":329,\"y\":55}],\"word\":\"应用版本\"}]},{\"col_end\":6,\"row_end\":1,\"cell_location\":[{\"x\":395,\"y\":25},{\"x\":566,\"y\":25},{\"x\":566,\"y\":66},{\"x\":395,\"y\":66}],\"row_start\":0,\"col_start\":5,\"words\":\"所涉问题\",\"contents\":[{\"poly_location\":[{\"x\":450,\"y\":39},{\"x\":507,\"y\":39},{\"x\":508,\"y\":55},{\"x\":450,\"y\":55}],\"word\":\"所涉问题\"}]},{\"col_end\":1,\"row_end\":2,\"cell_location\":[{\"x\":8,\"y\":66},{\"x\":53,\"y\":66},{\"x\":53,\"y\":130},{\"x\":8,\"y\":130}],\"row_start\":1,\"col_start\":0,\"words\":\"1\",\"contents\":[{\"poly_location\":[{\"x\":24,\"y\":90},{\"x\":32,\"y\":89},{\"x\":33,\"y\":102},{\"x\":26,\"y\":103}],\"word\":\"1\"}]},{\"col_end\":2,\"row_end\":2,\"cell_location\":[{\"x\":53,\"y\":66},{\"x\":126,\"y\":66},{\"x\":126,\"y\":130},{\"x\":53,\"y\":130}],\"row_start\":1,\"col_start\":1,\"words\":\"快看\",\"contents\":[{\"poly_location\":[{\"x\":71,\"y\":87},{\"x\":101,\"y\":87},{\"x\":101,\"y\":105},{\"x\":71,\"y\":105}],\"word\":\"快看\"}]},{\"col_end\":3,\"row_end\":2,\"cell_location\":[{\"x\":126,\"y\":66},{\"x\":237,\"y\":66},{\"x\":237,\"y\":130},{\"x\":126,\"y\":130}],\"row_start\":1,\"col_start\":2,\"words\":\"快看世界（北京）\\n科技有限公司\",\"contents\":[{\"poly_location\":[{\"x\":124,\"y\":72},{\"x\":230,\"y\":72},{\"x\":230,\"y\":88},{\"x\":124,\"y\":88}],\"word\":\"快看世界（北京）\"},{\"poly_location\":[{\"x\":135,\"y\":105},{\"x\":219,\"y\":105},{\"x\":219,\"y\":120},{\"x\":135,\"y\":120}],\"word\":\"科技有限公司\"}]},{\"col_end\":4,\"row_end\":2,\"cell_location\":[{\"x\":237,\"y\":66},{\"x\":325,\"y\":66},{\"x\":325,\"y\":130},{\"x\":237,\"y\":130}],\"row_start\":1,\"col_start\":3,\"words\":\"华为应用市场\",\"contents\":[{\"poly_location\":[{\"x\":235,\"y\":88},{\"x\":320,\"y\":88},{\"x\":320,\"y\":104},{\"x\":235,\"y\":104}],\"word\":\"华为应用市场\"}]},{\"col_end\":5,\"row_end\":2,\"cell_location\":[{\"x\":325,\"y\":66},{\"x\":395,\"y\":66},{\"x\":395,\"y\":130},{\"x\":325,\"y\":130}],\"row_start\":1,\"col_start\":4,\"words\":\"7.28.0\",\"contents\":[{\"poly_location\":[{\"x\":337,\"y\":90},{\"x\":380,\"y\":90},{\"x\":380,\"y\":102},{\"x\":337,\"y\":102}],\"word\":\"7.28.0\"}]},{\"col_end\":6,\"row_end\":2,\"cell_location\":[{\"x\":395,\"y\":66},{\"x\":566,\"y\":66},{\"x\":566,\"y\":130},{\"x\":395,\"y\":130}],\"row_start\":1,\"col_start\":5,\"words\":\"违规推送弹窗信息\",\"contents\":[{\"poly_location\":[{\"x\":394,\"y\":89},{\"x\":507,\"y\":89},{\"x\":507,\"y\":103},{\"x\":394,\"y\":103}],\"word\":\"违规推送弹窗信息\"}]},{\"col_end\":1,\"row_end\":3,\"cell_location\":[{\"x\":8,\"y\":130},{\"x\":53,\"y\":130},{\"x\":53,\"y\":194},{\"x\":8,\"y\":194}],\"row_start\":2,\"col_start\":0,\"words\":\"2\",\"contents\":[{\"poly_location\":[{\"x\":25,\"y\":155},{\"x\":33,\"y\":155},{\"x\":33,\"y\":167},{\"x\":25,\"y\":167}],\"word\":\"2\"}]},{\"col_end\":2,\"row_end\":3,\"cell_location\":[{\"x\":53,\"y\":130},{\"x\":126,\"y\":130},{\"x\":126,\"y\":194},{\"x\":53,\"y\":194}],\"row_start\":2,\"col_start\":1,\"words\":\"玩吧\",\"contents\":[{\"poly_location\":[{\"x\":71,\"y\":153},{\"x\":101,\"y\":153},{\"x\":101,\"y\":169},{\"x\":71,\"y\":169}],\"word\":\"玩吧\"}]},{\"col_end\":3,\"row_end\":3,\"cell_location\":[{\"x\":126,\"y\":130},{\"x\":237,\"y\":130},{\"x\":237,\"y\":194},{\"x\":126,\"y\":194}],\"row_start\":2,\"col_start\":2,\"words\":\"北京默契破冰科\\n技有限公司\",\"contents\":[{\"poly_location\":[{\"x\":128,\"y\":137},{\"x\":227,\"y\":137},{\"x\":227,\"y\":153},{\"x\":128,\"y\":153}],\"word\":\"北京默契破冰科\"},{\"poly_location\":[{\"x\":142,\"y\":169},{\"x\":212,\"y\":169},{\"x\":212,\"y\":185},{\"x\":142,\"y\":185}],\"word\":\"技有限公司\"}]},{\"col_end\":4,\"row_end\":3,\"cell_location\":[{\"x\":237,\"y\":130},{\"x\":325,\"y\":130},{\"x\":325,\"y\":194},{\"x\":237,\"y\":194}],\"row_start\":2,\"col_start\":3,\"words\":\"vivo应用商店\",\"contents\":[{\"poly_location\":[{\"x\":234,\"y\":154},{\"x\":320,\"y\":154},{\"x\":320,\"y\":168},{\"x\":234,\"y\":168}],\"word\":\"vivo应用商店\"}]},{\"col_end\":5,\"row_end\":3,\"cell_location\":[{\"x\":325,\"y\":130},{\"x\":395,\"y\":130},{\"x\":395,\"y\":194},{\"x\":325,\"y\":194}],\"row_start\":2,\"col_start\":4,\"words\":\"10.48.2\",\"contents\":[{\"poly_location\":[{\"x\":334,\"y\":155},{\"x\":382,\"y\":155},{\"x\":382,\"y\":167},{\"x\":334,\"y\":167}],\"word\":\"10.48.2\"}]},{\"col_end\":6,\"row_end\":3,\"cell_location\":[{\"x\":395,\"y\":130},{\"x\":566,\"y\":130},{\"x\":566,\"y\":194},{\"x\":395,\"y\":194}],\"row_start\":2,\"col_start\":5,\"words\":\"违规推送弹窗信息\",\"contents\":[{\"poly_location\":[{\"x\":394,\"y\":154},{\"x\":507,\"y\":154},{\"x\":507,\"y\":168},{\"x\":394,\"y\":168}],\"word\":\"违规推送弹窗信息\"}]},{\"col_end\":1,\"row_end\":4,\"cell_location\":[{\"x\":8,\"y\":194},{\"x\":53,\"y\":194},{\"x\":53,\"y\":260},{\"x\":8,\"y\":260}],\"row_start\":3,\"col_start\":0,\"words\":\"3\",\"contents\":[{\"poly_location\":[{\"x\":25,\"y\":219},{\"x\":34,\"y\":219},{\"x\":34,\"y\":232},{\"x\":25,\"y\":232}],\"word\":\"3\"}]},{\"col_end\":2,\"row_end\":4,\"cell_location\":[{\"x\":53,\"y\":194},{\"x\":126,\"y\":194},{\"x\":126,\"y\":260},{\"x\":53,\"y\":260}],\"row_start\":3,\"col_start\":1,\"words\":\"快音\",\"contents\":[{\"poly_location\":[{\"x\":71,\"y\":217},{\"x\":101,\"y\":217},{\"x\":101,\"y\":235},{\"x\":71,\"y\":235}],\"word\":\"快音\"}]},{\"col_end\":3,\"row_end\":4,\"cell_location\":[{\"x\":126,\"y\":194},{\"x\":237,\"y\":194},{\"x\":237,\"y\":260},{\"x\":126,\"y\":260}],\"row_start\":3,\"col_start\":2,\"words\":\"成都开心音符科\\n技有限公司\",\"contents\":[{\"poly_location\":[{\"x\":129,\"y\":202},{\"x\":227,\"y\":202},{\"x\":227,\"y\":218},{\"x\":129,\"y\":218}],\"word\":\"成都开心音符科\"},{\"poly_location\":[{\"x\":142,\"y\":234},{\"x\":212,\"y\":234},{\"x\":212,\"y\":250},{\"x\":142,\"y\":250}],\"word\":\"技有限公司\"}]},{\"col_end\":4,\"row_end\":4,\"cell_location\":[{\"x\":237,\"y\":194},{\"x\":325,\"y\":194},{\"x\":325,\"y\":260},{\"x\":237,\"y\":260}],\"row_start\":3,\"col_start\":3,\"words\":\"vivo应用商店\",\"contents\":[{\"poly_location\":[{\"x\":234,\"y\":219},{\"x\":320,\"y\":219},{\"x\":320,\"y\":233},{\"x\":234,\"y\":233}],\"word\":\"vivo应用商店\"}]},{\"col_end\":5,\"row_end\":4,\"cell_location\":[{\"x\":325,\"y\":194},{\"x\":395,\"y\":194},{\"x\":395,\"y\":260},{\"x\":325,\"y\":260}],\"row_start\":3,\"col_start\":4,\"words\":\"5.20.15\",\"contents\":[{\"poly_location\":[{\"x\":333,\"y\":220},{\"x\":382,\"y\":220},{\"x\":382,\"y\":232},{\"x\":333,\"y\":232}],\"word\":\"5.20.15\"}]},{\"col_end\":6,\"row_end\":4,\"cell_location\":[{\"x\":395,\"y\":194},{\"x\":566,\"y\":194},{\"x\":567,\"y\":260},{\"x\":395,\"y\":260}],\"row_start\":3,\"col_start\":5,\"words\":\"违规推送弹窗信息\",\"contents\":[{\"poly_location\":[{\"x\":394,\"y\":219},{\"x\":507,\"y\":219},{\"x\":507,\"y\":233},{\"x\":394,\"y\":233}],\"word\":\"违规推送弹窗信息\"}]},{\"col_end\":1,\"row_end\":5,\"cell_location\":[{\"x\":8,\"y\":260},{\"x\":53,\"y\":260},{\"x\":53,\"y\":324},{\"x\":8,\"y\":324}],\"row_start\":4,\"col_start\":0,\"words\":\"\",\"contents\":[]},{\"col_end\":2,\"row_end\":5,\"cell_location\":[{\"x\":53,\"y\":260},{\"x\":126,\"y\":260},{\"x\":126,\"y\":324},{\"x\":53,\"y\":324}],\"row_start\":4,\"col_start\":1,\"words\":\"糖豆\",\"contents\":[{\"poly_location\":[{\"x\":71,\"y\":283},{\"x\":101,\"y\":283},{\"x\":101,\"y\":299},{\"x\":71,\"y\":299}],\"word\":\"糖豆\"}]},{\"col_end\":3,\"row_end\":5,\"cell_location\":[{\"x\":126,\"y\":260},{\"x\":237,\"y\":260},{\"x\":237,\"y\":324},{\"x\":126,\"y\":324}],\"row_start\":4,\"col_start\":2,\"words\":\"小糖互娱（北京）\\n科技有限公司\",\"contents\":[{\"poly_location\":[{\"x\":123,\"y\":267},{\"x\":230,\"y\":267},{\"x\":230,\"y\":283},{\"x\":123,\"y\":283}],\"word\":\"小糖互娱（北京）\"},{\"poly_location\":[{\"x\":135,\"y\":300},{\"x\":219,\"y\":300},{\"x\":219,\"y\":314},{\"x\":135,\"y\":314}],\"word\":\"科技有限公司\"}]},{\"col_end\":4,\"row_end\":5,\"cell_location\":[{\"x\":237,\"y\":260},{\"x\":325,\"y\":260},{\"x\":325,\"y\":324},{\"x\":237,\"y\":324}],\"row_start\":4,\"col_start\":3,\"words\":\"小米应用商店\",\"contents\":[{\"poly_location\":[{\"x\":234,\"y\":283},{\"x\":319,\"y\":283},{\"x\":319,\"y\":299},{\"x\":234,\"y\":299}],\"word\":\"小米应用商店\"}]},{\"col_end\":5,\"row_end\":5,\"cell_location\":[{\"x\":325,\"y\":260},{\"x\":395,\"y\":260},{\"x\":395,\"y\":324},{\"x\":325,\"y\":324}],\"row_start\":4,\"col_start\":4,\"words\":\"7.8.3\",\"contents\":[{\"poly_location\":[{\"x\":340,\"y\":285},{\"x\":376,\"y\":285},{\"x\":376,\"y\":297},{\"x\":340,\"y\":297}],\"word\":\"7.8.3\"}]},{\"col_end\":6,\"row_end\":5,\"cell_location\":[{\"x\":395,\"y\":260},{\"x\":567,\"y\":260},{\"x\":567,\"y\":324},{\"x\":395,\"y\":324}],\"row_start\":4,\"col_start\":5,\"words\":\"违规推送弹窗信息\",\"contents\":[{\"poly_location\":[{\"x\":394,\"y\":284},{\"x\":507,\"y\":284},{\"x\":507,\"y\":298},{\"x\":394,\"y\":298}],\"word\":\"违规推送弹窗信息\"}]},{\"col_end\":1,\"row_end\":6,\"cell_location\":[{\"x\":8,\"y\":324},{\"x\":53,\"y\":324},{\"x\":53,\"y\":390},{\"x\":8,\"y\":390}],\"row_start\":5,\"col_start\":0,\"words\":\"5\",\"contents\":[{\"poly_location\":[{\"x\":26,\"y\":350},{\"x\":34,\"y\":350},{\"x\":33,\"y\":363},{\"x\":25,\"y\":362}],\"word\":\"5\"}]},{\"col_end\":2,\"row_end\":6,\"cell_location\":[{\"x\":53,\"y\":324},{\"x\":126,\"y\":324},{\"x\":126,\"y\":390},{\"x\":53,\"y\":390}],\"row_start\":5,\"col_start\":1,\"words\":\"爆米花视\\n频\",\"contents\":[{\"poly_location\":[{\"x\":57,\"y\":332},{\"x\":115,\"y\":331},{\"x\":115,\"y\":348},{\"x\":57,\"y\":348}],\"word\":\"爆米花视\"},{\"poly_location\":[{\"x\":77,\"y\":362},{\"x\":94,\"y\":362},{\"x\":94,\"y\":380},{\"x\":77,\"y\":380}],\"word\":\"频\"}]},{\"col_end\":3,\"row_end\":6,\"cell_location\":[{\"x\":126,\"y\":324},{\"x\":237,\"y\":324},{\"x\":237,\"y\":390},{\"x\":126,\"y\":390}],\"row_start\":5,\"col_start\":2,\"words\":\"爆米花（杭州）科\\n技有限公司\",\"contents\":[{\"poly_location\":[{\"x\":123,\"y\":332},{\"x\":231,\"y\":332},{\"x\":231,\"y\":348},{\"x\":123,\"y\":348}],\"word\":\"爆米花（杭州）科\"},{\"poly_location\":[{\"x\":142,\"y\":363},{\"x\":212,\"y\":363},{\"x\":212,\"y\":379},{\"x\":142,\"y\":379}],\"word\":\"技有限公司\"}]},{\"col_end\":4,\"row_end\":6,\"cell_location\":[{\"x\":237,\"y\":324},{\"x\":325,\"y\":324},{\"x\":325,\"y\":390},{\"x\":237,\"y\":390}],\"row_start\":5,\"col_start\":3,\"words\":\"小米应用商店\",\"contents\":[{\"poly_location\":[{\"x\":235,\"y\":349},{\"x\":319,\"y\":349},{\"x\":319,\"y\":363},{\"x\":235,\"y\":363}],\"word\":\"小米应用商店\"}]},{\"col_end\":5,\"row_end\":6,\"cell_location\":[{\"x\":325,\"y\":324},{\"x\":395,\"y\":324},{\"x\":395,\"y\":390},{\"x\":325,\"y\":390}],\"row_start\":5,\"col_start\":4,\"words\":\"12.8.2.0\",\"contents\":[{\"poly_location\":[{\"x\":330,\"y\":350},{\"x\":386,\"y\":350},{\"x\":386,\"y\":362},{\"x\":330,\"y\":362}],\"word\":\"12.8.2.0\"}]},{\"col_end\":6,\"row_end\":6,\"cell_location\":[{\"x\":395,\"y\":324},{\"x\":567,\"y\":324},{\"x\":567,\"y\":390},{\"x\":395,\"y\":390}],\"row_start\":5,\"col_start\":5,\"words\":\"违规推送弹窗信息\",\"contents\":[{\"poly_location\":[{\"x\":394,\"y\":349},{\"x\":507,\"y\":349},{\"x\":507,\"y\":363},{\"x\":394,\"y\":363}],\"word\":\"违规推送弹窗信息\"}]},{\"col_end\":1,\"row_end\":7,\"cell_location\":[{\"x\":8,\"y\":390},{\"x\":53,\"y\":390},{\"x\":53,\"y\":454},{\"x\":8,\"y\":454}],\"row_start\":6,\"col_start\":0,\"words\":\"6\",\"contents\":[{\"poly_location\":[{\"x\":26,\"y\":414},{\"x\":34,\"y\":414},{\"x\":34,\"y\":426},{\"x\":26,\"y\":426}],\"word\":\"6\"}]},{\"col_end\":2,\"row_end\":7,\"cell_location\":[{\"x\":53,\"y\":390},{\"x\":126,\"y\":390},{\"x\":126,\"y\":454},{\"x\":53,\"y\":454}],\"row_start\":6,\"col_start\":1,\"words\":\"简单天气\",\"contents\":[{\"poly_location\":[{\"x\":58,\"y\":412},{\"x\":114,\"y\":412},{\"x\":114,\"y\":428},{\"x\":58,\"y\":428}],\"word\":\"简单天气\"}]},{\"col_end\":3,\"row_end\":7,\"cell_location\":[{\"x\":126,\"y\":390},{\"x\":237,\"y\":390},{\"x\":237,\"y\":454},{\"x\":126,\"y\":454}],\"row_start\":6,\"col_start\":2,\"words\":\"上海脉炬网络科\\n技有限公司\",\"contents\":[{\"poly_location\":[{\"x\":131,\"y\":397},{\"x\":226,\"y\":397},{\"x\":226,\"y\":411},{\"x\":131,\"y\":411}],\"word\":\"上海脉炬网络科\"},{\"poly_location\":[{\"x\":142,\"y\":428},{\"x\":212,\"y\":428},{\"x\":212,\"y\":444},{\"x\":142,\"y\":444}],\"word\":\"技有限公司\"}]},{\"col_end\":4,\"row_end\":7,\"cell_location\":[{\"x\":237,\"y\":390},{\"x\":325,\"y\":390},{\"x\":325,\"y\":454},{\"x\":237,\"y\":454}],\"row_start\":6,\"col_start\":3,\"words\":\"App Store \",\"contents\":[{\"poly_location\":[{\"x\":245,\"y\":414},{\"x\":310,\"y\":414},{\"x\":310,\"y\":427},{\"x\":246,\"y\":428}],\"word\":\"App Store \"}]},{\"col_end\":5,\"row_end\":7,\"cell_location\":[{\"x\":325,\"y\":390},{\"x\":395,\"y\":390},{\"x\":396,\"y\":454},{\"x\":325,\"y\":454}],\"row_start\":6,\"col_start\":4,\"words\":\"1.5.8\",\"contents\":[{\"poly_location\":[{\"x\":340,\"y\":414},{\"x\":376,\"y\":414},{\"x\":376,\"y\":426},{\"x\":340,\"y\":426}],\"word\":\"1.5.8\"}]},{\"col_end\":6,\"row_end\":7,\"cell_location\":[{\"x\":395,\"y\":390},{\"x\":567,\"y\":390},{\"x\":567,\"y\":454},{\"x\":396,\"y\":454}],\"row_start\":6,\"col_start\":5,\"words\":\"违规推送弹窗信息\",\"contents\":[{\"poly_location\":[{\"x\":394,\"y\":413},{\"x\":507,\"y\":413},{\"x\":507,\"y\":427},{\"x\":394,\"y\":427}],\"word\":\"违规推送弹窗信息\"}]},{\"col_end\":1,\"row_end\":9,\"cell_location\":[{\"x\":8,\"y\":454},{\"x\":53,\"y\":454},{\"x\":53,\"y\":584},{\"x\":8,\"y\":584}],\"row_start\":7,\"col_start\":0,\"words\":\"\",\"contents\":[]},{\"col_end\":2,\"row_end\":9,\"cell_location\":[{\"x\":53,\"y\":454},{\"x\":126,\"y\":454},{\"x\":126,\"y\":584},{\"x\":53,\"y\":584}],\"row_start\":7,\"col_start\":1,\"words\":\"熊出没之\\n熊大农场\",\"contents\":[{\"poly_location\":[{\"x\":58,\"y\":494},{\"x\":114,\"y\":494},{\"x\":114,\"y\":510},{\"x\":58,\"y\":510}],\"word\":\"熊出没之\"},{\"poly_location\":[{\"x\":58,\"y\":525},{\"x\":114,\"y\":525},{\"x\":114,\"y\":541},{\"x\":58,\"y\":541}],\"word\":\"熊大农场\"}]},{\"col_end\":3,\"row_end\":8,\"cell_location\":[{\"x\":126,\"y\":454},{\"x\":237,\"y\":454},{\"x\":237,\"y\":519},{\"x\":126,\"y\":519}],\"row_start\":7,\"col_start\":2,\"words\":\"乐堂动漫信息技\\n术有限公司\",\"contents\":[{\"poly_location\":[{\"x\":128,\"y\":462},{\"x\":227,\"y\":462},{\"x\":227,\"y\":477},{\"x\":128,\"y\":477}],\"word\":\"乐堂动漫信息技\"},{\"poly_location\":[{\"x\":142,\"y\":494},{\"x\":212,\"y\":494},{\"x\":212,\"y\":509},{\"x\":142,\"y\":509}],\"word\":\"术有限公司\"}]},{\"col_end\":4,\"row_end\":8,\"cell_location\":[{\"x\":237,\"y\":454},{\"x\":325,\"y\":454},{\"x\":325,\"y\":519},{\"x\":237,\"y\":519}],\"row_start\":7,\"col_start\":3,\"words\":\"App Store \",\"contents\":[{\"poly_location\":[{\"x\":245,\"y\":479},{\"x\":310,\"y\":479},{\"x\":310,\"y\":492},{\"x\":246,\"y\":493}],\"word\":\"App Store \"}]},{\"col_end\":5,\"row_end\":8,\"cell_location\":[{\"x\":325,\"y\":454},{\"x\":396,\"y\":454},{\"x\":396,\"y\":519},{\"x\":325,\"y\":519}],\"row_start\":7,\"col_start\":4,\"words\":\"2.2.2\",\"contents\":[{\"poly_location\":[{\"x\":340,\"y\":479},{\"x\":375,\"y\":479},{\"x\":375,\"y\":491},{\"x\":340,\"y\":491}],\"word\":\"2.2.2\"}]},{\"col_end\":6,\"row_end\":8,\"cell_location\":[{\"x\":396,\"y\":454},{\"x\":567,\"y\":454},{\"x\":567,\"y\":519},{\"x\":396,\"y\":519}],\"row_start\":7,\"col_start\":5,\"words\":\"违规推送弹窗信息\",\"contents\":[{\"poly_location\":[{\"x\":394,\"y\":478},{\"x\":507,\"y\":478},{\"x\":507,\"y\":492},{\"x\":394,\"y\":492}],\"word\":\"违规推送弹窗信息\"}]},{\"col_end\":3,\"row_end\":9,\"cell_location\":[{\"x\":126,\"y\":519},{\"x\":237,\"y\":519},{\"x\":237,\"y\":584},{\"x\":126,\"y\":584}],\"row_start\":8,\"col_start\":2,\"words\":\"合肥乐堂动漫信\\n息技术有限公司\",\"contents\":[{\"poly_location\":[{\"x\":128,\"y\":526},{\"x\":226,\"y\":526},{\"x\":226,\"y\":542},{\"x\":128,\"y\":542}],\"word\":\"合肥乐堂动漫信\"},{\"poly_location\":[{\"x\":128,\"y\":558},{\"x\":226,\"y\":558},{\"x\":226,\"y\":573},{\"x\":128,\"y\":573}],\"word\":\"息技术有限公司\"}]},{\"col_end\":4,\"row_end\":9,\"cell_location\":[{\"x\":237,\"y\":519},{\"x\":325,\"y\":519},{\"x\":325,\"y\":584},{\"x\":237,\"y\":584}],\"row_start\":8,\"col_start\":3,\"words\":\"应用宝\",\"contents\":[{\"poly_location\":[{\"x\":257,\"y\":542},{\"x\":299,\"y\":542},{\"x\":299,\"y\":558},{\"x\":257,\"y\":558}],\"word\":\"应用宝\"}]},{\"col_end\":5,\"row_end\":9,\"cell_location\":[{\"x\":325,\"y\":519},{\"x\":396,\"y\":519},{\"x\":396,\"y\":584},{\"x\":325,\"y\":584}],\"row_start\":8,\"col_start\":4,\"words\":\"1.7.0\",\"contents\":[{\"poly_location\":[{\"x\":340,\"y\":544},{\"x\":376,\"y\":544},{\"x\":376,\"y\":556},{\"x\":340,\"y\":556}],\"word\":\"1.7.0\"}]},{\"col_end\":6,\"row_end\":9,\"cell_location\":[{\"x\":396,\"y\":519},{\"x\":567,\"y\":519},{\"x\":567,\"y\":584},{\"x\":396,\"y\":584}],\"row_start\":8,\"col_start\":5,\"words\":\"违规推送弹窗信息\",\"contents\":[{\"poly_location\":[{\"x\":394,\"y\":543},{\"x\":507,\"y\":543},{\"x\":507,\"y\":557},{\"x\":394,\"y\":557}],\"word\":\"违规推送弹窗信息\"}]},{\"col_end\":1,\"row_end\":10,\"cell_location\":[{\"x\":8,\"y\":584},{\"x\":53,\"y\":584},{\"x\":53,\"y\":645},{\"x\":8,\"y\":645}],\"row_start\":9,\"col_start\":0,\"words\":\"8\",\"contents\":[{\"poly_location\":[{\"x\":25,\"y\":609},{\"x\":33,\"y\":609},{\"x\":33,\"y\":621},{\"x\":25,\"y\":621}],\"word\":\"8\"}]},{\"col_end\":2,\"row_end\":10,\"cell_location\":[{\"x\":53,\"y\":584},{\"x\":126,\"y\":584},{\"x\":126,\"y\":645},{\"x\":53,\"y\":645}],\"row_start\":9,\"col_start\":1,\"words\":\"2345浏览\",\"contents\":[{\"poly_location\":[{\"x\":56,\"y\":591},{\"x\":116,\"y\":591},{\"x\":116,\"y\":607},{\"x\":56,\"y\":607}],\"word\":\"2345浏览\"}]},{\"col_end\":3,\"row_end\":10,\"cell_location\":[{\"x\":126,\"y\":584},{\"x\":237,\"y\":584},{\"x\":237,\"y\":645},{\"x\":126,\"y\":645}],\"row_start\":9,\"col_start\":2,\"words\":\"上海二三四五移\\n动科技有限公司\",\"contents\":[{\"poly_location\":[{\"x\":130,\"y\":592},{\"x\":226,\"y\":592},{\"x\":226,\"y\":606},{\"x\":130,\"y\":606}],\"word\":\"上海二三四五移\"},{\"poly_location\":[{\"x\":128,\"y\":623},{\"x\":225,\"y\":623},{\"x\":225,\"y\":638},{\"x\":128,\"y\":638}],\"word\":\"动科技有限公司\"}]},{\"col_end\":4,\"row_end\":10,\"cell_location\":[{\"x\":237,\"y\":584},{\"x\":325,\"y\":584},{\"x\":325,\"y\":645},{\"x\":237,\"y\":645}],\"row_start\":9,\"col_start\":3,\"words\":\"百度手机助手\",\"contents\":[{\"poly_location\":[{\"x\":236,\"y\":607},{\"x\":320,\"y\":607},{\"x\":320,\"y\":623},{\"x\":236,\"y\":623}],\"word\":\"百度手机助手\"}]},{\"col_end\":5,\"row_end\":10,\"cell_location\":[{\"x\":325,\"y\":584},{\"x\":396,\"y\":584},{\"x\":396,\"y\":645},{\"x\":325,\"y\":645}],\"row_start\":9,\"col_start\":4,\"words\":\"15.6.0\",\"contents\":[{\"poly_location\":[{\"x\":337,\"y\":609},{\"x\":379,\"y\":609},{\"x\":379,\"y\":621},{\"x\":337,\"y\":621}],\"word\":\"15.6.0\"}]},{\"col_end\":6,\"row_end\":10,\"cell_location\":[{\"x\":396,\"y\":584},{\"x\":567,\"y\":584},{\"x\":567,\"y\":645},{\"x\":396,\"y\":645}],\"row_start\":9,\"col_start\":5,\"words\":\"违规推送弹窗信息\",\"contents\":[{\"poly_location\":[{\"x\":394,\"y\":608},{\"x\":508,\"y\":608},{\"x\":508,\"y\":622},{\"x\":394,\"y\":622}],\"word\":\"违规推送弹窗信息\"}]}],\"table_location\":[{\"x\":8,\"y\":25},{\"x\":567,\"y\":25},{\"x\":567,\"y\":645},{\"x\":8,\"y\":645}],\"footer\":[]}],\"table_num\":1,\"log_id\":1638451711117144300}";
            Map<String, Object> map = JSONObject.parseObject(responseStr, Map.class);

            String headStr =
                    JSONObject.parseObject(
                            JSONObject.parseObject(
                                    JSONObject.parseObject(
                                            JSONObject.parseObject(
                                                    map.get("tables_result") + "", List.class).get(0) + "", Map.class).get("header") + "", List.class).get(0) + "", Map.class).get("words") + "";

            List<Map<String, Object>> bodyList =
                    JSONObject.parseObject(
                            JSONObject.parseObject(
                                    JSONObject.parseObject(map.get("tables_result") + "", List.class).get(0) + "", Map.class).get("body") + "", List.class);

            List<Map<String, String>> resultList = new ArrayList<>();
            int row = 1;
            int row_con = 1;
            System.out.println(headStr);

            List<Map<String, String>> tempList = new ArrayList<>();
            Map<String, String> tempMap = new HashMap<>();
            for (int i = 0; i < bodyList.size(); i++) {
                Map<String, Object> objectMap = bodyList.get(i);
                if (row == Integer.parseInt(objectMap.get("row_end") + "")) {
                    System.out.print(("(" + objectMap.get("row_end") + "," + objectMap.get("col_end") + ")" + objectMap.get("words") + "  |  ").replace("\n", ""));
                    tempMap.put("(" + objectMap.get("row_end") + "," + objectMap.get("col_end") + ")", (objectMap.get("words") + "").replace("\n", ""));
                } else if (Integer.parseInt(objectMap.get("row_end") + "") - row > 1) {
                    Map<String, String> tempMap2 = new HashMap<>();
                    tempMap2.putAll(tempMap);
                    tempList.add(tempMap2);
                    tempMap.clear();
                    System.out.println();
                    row_con = Integer.parseInt(objectMap.get("row_end") + "") - row; // 别删
                    row = Integer.parseInt(objectMap.get("row_end") + "");
                    System.out.print(("\n(" + objectMap.get("row_end") + "," + objectMap.get("col_end") + ")" + objectMap.get("words") + "  |  ").replace("\n", ""));
                    tempMap.put("(" + objectMap.get("row_end") + "," + objectMap.get("col_end") + ")", (objectMap.get("words") + "").replace("\n", ""));
                } else if (Integer.parseInt(objectMap.get("row_end") + "") - row < 1) {
                    row_con = Integer.parseInt(objectMap.get("row_end") + "") - row;
                    System.out.print(("\n(" + objectMap.get("row_end") + "," + objectMap.get("col_end") + ")" + objectMap.get("words") + "  |  ").replace("\n", ""));
                    tempMap.put("(" + objectMap.get("row_end") + "," + objectMap.get("col_end") + ")", (objectMap.get("words") + "").replace("\n", ""));
                } else {
                    Map<String, String> tempMap2 = new HashMap<>();
                    tempMap2.putAll(tempMap);
                    tempList.add(tempMap2);
                    tempMap.clear();
                    row_con = 1;
                    System.out.println();
                    row = Integer.parseInt(objectMap.get("row_end") + "");
                    System.out.print(("\n(" + objectMap.get("row_end") + "," + objectMap.get("col_end") + ")" + objectMap.get("words") + "  |  ").replace("\n", ""));
                    tempMap.put("(" + objectMap.get("row_end") + "," + objectMap.get("col_end") + ")", (objectMap.get("words") + "").replace("\n", ""));
                }
            }
            tempList.add(tempMap);
            System.out.println();
            // 整理数据
            int shift = 1;
            List<Map<String, String>> mapList = new ArrayList<>();
            for (int i = 0; i < tempList.size(); i++) {
                if (tempList.get(i).size() == 6) {
                    Map<String, String> map1 = tempList.get(i);
                    Map<String, String> objMap = new HashMap<>();
                    Set keySet = map1.keySet();  // 获取 key 集合对象
                    for (Object keyName : keySet) {
                        System.out.print("键名:" + keyName);  //输出键名
                        if (String.valueOf(keyName).equals("(" + (i + shift) + ",1)")) {
                            objMap.put("sort", map1.get(keyName));
                        } else if (String.valueOf(keyName).equals("(" + (i + shift) + ",2)")) {
                            objMap.put("pname", map1.get(keyName));
                        } else if (String.valueOf(keyName).equals("(" + (i + shift) + ",3)")) {
                            objMap.put("developer", map1.get(keyName));
                        } else if (String.valueOf(keyName).equals("(" + (i + shift) + ",4)")) {
                            objMap.put("source", map1.get(keyName));
                        } else if (String.valueOf(keyName).equals("(" + (i + shift) + ",5)")) {
                            objMap.put("version", map1.get(keyName));
                        } else if (String.valueOf(keyName).equals("(" + (i + shift) + ",6)")) {
                            objMap.put("issues", map1.get(keyName));
                        }
//                    }
                    }
                    mapList.add(objMap);
                    System.out.println();
                    shift = 1;
                } else {
                    Map<String, String> map1 = tempList.get(i);
                    Map<String, String> objMap = new HashMap<>();

                    // 获取 key 集合对象
                    Set keySet = map1.keySet();
                    // 查找数据的范围
                    int row_cont2 = 1;
                    for (Object keyName : keySet) {
                        row_cont2 = row_cont2 > Integer.parseInt(String.valueOf(keyName).substring(1, 2)) - i ? row_cont2 : Integer.parseInt(String.valueOf(keyName).substring(1, 2)) - i;
                    }
                    // 将缺失数据不全
                    for (int colNum = 1; colNum <= 6; colNum++) {
                        if (!keySet.contains("(" + (i + 1) + "," + colNum + ")")) {
                            map1.put("(" + (i + 1) + "," + colNum + ")", map1.get("(" + (i + row_cont2) + "," + colNum + ")"));
                        }
                    }
                    // 然后进行分割
                    List<Map<String, String>> tempMapList = new ArrayList<>();
                    // 获取 key 集合对象
                    Set keySet2 = map1.keySet();
                    Set<String> rowSet = new HashSet<>();
                    for (Object keyName : keySet2) {
                        rowSet.add(String.valueOf(keyName).substring(1, 2));
                    }
                    for (String x : rowSet) {
                        Map<String, String> tempObjMap = new HashMap<>();
                        for (int colNum = 1; colNum <= 6; colNum++) {
                            for (Object keyName : keySet2) {
                                if (String.valueOf(keyName).equals("(" + x + ",1)")) {
                                    tempObjMap.put("sort", map1.get("(" + x + ",1)"));
                                } else if (String.valueOf(keyName).equals("(" + x + ",2)")) {
                                    tempObjMap.put("pname", map1.get("(" + x + ",2)"));
                                } else if (String.valueOf(keyName).equals("(" + x + ",3)")) {
                                    tempObjMap.put("developer", map1.get("(" + x + ",3)"));
                                } else if (String.valueOf(keyName).equals("(" + x + ",4)")) {
                                    tempObjMap.put("source", map1.get("(" + x + ",4)"));
                                } else if (String.valueOf(keyName).equals("(" + x + ",5)")) {
                                    tempObjMap.put("version", map1.get("(" + x + ",5)"));
                                } else if (String.valueOf(keyName).equals("(" + x + ",6)")) {
                                    tempObjMap.put("issues", map1.get("(" + x + ",6)"));
                                }
                            }
                        }
                        mapList.add(tempObjMap);
                    }
                    shift = shift + row_cont2 - 1;
                }
            }
            System.out.println(mapList);

            // 保存数据



            logger.info(String.format("识别图片完成耗时: %s", System.currentTimeMillis() - start));
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }

    /**
     * 获取文件base64编码
     *
     * @param path 文件路径
     * @return base64编码信息，不带文件头
     * @throws IOException IO异常
     */
    static String getFileContentAsBase64(String path) throws IOException {
        byte[] b = Files.readAllBytes(Paths.get(path));
        return Base64.getEncoder().encodeToString(b);
    }

    /**
     * 获取文件base64 UrlEncode编码
     *
     * @param path 文件路径
     * @return base64编码信息，不带文件头
     * @throws IOException IO异常
     */
    static String getFileContentAsBase64Urlencoded(String path) throws IOException {
        return URLEncoder.encode(getFileContentAsBase64(path), "utf-8");
    }


}
